/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package RemoteDesktop;

import java.awt.Robot;
import java.io.IOException;
import java.net.Socket;
import java.util.Scanner;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Oho
 */
public class ServerDelegate extends Thread {
    Socket sk ;
    Robot rb ;
    public ServerDelegate(Socket sk ,Robot rb)
    {
        this.sk = sk ;
        this.rb = rb;
    }
    @Override
    public void run()
    {
        try {   
            Scanner scanner = null;
            scanner = new Scanner(sk.getInputStream());
            while(true)
            {
                int command = scanner.nextInt();
                System.out.println("New command: " + command);
                switch(command){
                    case -1:
                        rb.mousePress(scanner.nextInt());
                    break;
                    case -2:
                        rb.mouseRelease(scanner.nextInt());
                    break;
                    case -3:
                        rb.keyPress(scanner.nextInt());
                    break;
                    case -4:
                        rb.keyRelease(scanner.nextInt());
                    break;
                    case -5:
                        rb.mouseMove(scanner.nextInt(), scanner.nextInt());
                     break;
                    
                   // break;

                
            }
        } 
        } catch (IOException ex) {
            Logger.getLogger(ServerDelegate.class.getName()).log(Level.SEVERE, null, ex);
        }
    
    }
    
}
